package com.ljx.Controller;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.ljx.Domain.MyThreadLocal;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {
    @Override
    public void insertFill(MetaObject metaObject) {
        //设置创建时间
        metaObject.setValue("createTime",LocalDateTime.now());
        //设置创建人
        metaObject.setValue("createUser", MyThreadLocal.getThreadLocal());
        //设置更新人
        metaObject.setValue("updateTime",LocalDateTime.now());
        //设置更新时间
        metaObject.setValue("updateUser", MyThreadLocal.getThreadLocal());
//        //清除threadlocal
//        MyThreadLocal.clearThreadLocal();
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        //设置更新人
        metaObject.setValue("updateTime",LocalDateTime.now());
        //设置更新时间
        metaObject.setValue("updateUser", MyThreadLocal.getThreadLocal());
//        //清除threadlocal
//        MyThreadLocal.clearThreadLocal();
    }
}
